<template>
  <PCard class="improve-information-con" :isCardBorder="true" :isHeadBottomBorder="false" :shadow="'never'"
    :bodyStyle="{ width: '100%' }">
    <!-- <div slot="header" class="card-title">
      <span class="title">dddddd</span>
    </div> -->

    <div class="body">
      <!-- <UpLoadFile ref="iic" :config="config"></UpLoadFile>
      <div class="btn-group">
        <Tips :tips="tips"></Tips>
        <a-button type="primary" block @click="btnEvent"> 确认已完成</a-button>
      </div> -->
      <a-result :status="status" :title="resTitle">
        <template #extra>
          <div class="btn-group">
            <div class="btn-item">
              <a-button :type="cancelConfig.type" v-bind="cancelConfig.attr" @click="btnEventClosed">
                {{cancelConfig.label}}
              </a-button>

            </div>
            <div class="btn-item">
              <a-button :type="confirmConfig.type" v-bind="confirmConfig.attr" @click="btnEventNew">
                {{confirmConfig.label}}
              </a-button>

            </div>
          </div>
        </template>
      </a-result>
    </div>

  </PCard>
</template>

<script>
import getDataForDB from '@/api/qsbBusinessManagement'
import Tips from './tips.vue'
const setNodeTypeList = {
  10: 1,
  11: 2,
}
export default {
  name: 'ImproveInformation',
  components: { Tips },
  props: {
    dataInfo: { type: Object },
    closeEvent: { type: Function }
  },
  data() {
    return {
      cancelConfig:{
        label:'取消',
        eventName:'default',
        type:'',
        attr:{}
      },
      confirmConfig:{
        label:'确定',
        eventName:'default',
        type:'primary',
        attr:{}
      },
      status:'warning',
      resTitle:'为保证您的业务能够顺利办理，请再次确认您是否已经完成本项验证！',
      param: {
        fileStatus: '',
        files: [], // { "fileName": "", "fileUrl": "" }
        id: '',
      },
      tips: '请务必完成首次办税登记后点击，若未完成会导致办理时间延长。',
      config: {
        readonly: false,  // 用于标记是否是可编辑的 此参数可选   默认值 false 表示可编辑   true 表示只读，不可编辑  getData
        dir: '/qsb/contract/', // 上传文件的地址
        required: true, // 文件上传必填校验 默认为false 不校验   当值为true时进行强制校验
        showCardList: ['card1'], // 'card2','card3'
        upLoadCardListConfig: [
          { type: '1', tips: '请上传首次办税登记截图', fileInfo: { name: '', url: '' } },
          // {type:'1',tips:'身份证人像面2',fileInfo:{name:'',url:''}},
          // {type:'1',tips:'',fileInfo:{name:'',url:''}}
        ], // 此项最多可以传两组值
        fielConfig: {
          type: '图片', // 允许上传的文件类型 当为空时表示不限制  默认为空   可供选择类型： 图片  文档  压缩包  发票
          size: 10, // 允许上传的文件个数  默认值为1
          singleFileSize: 100, //上传的单个文件大小 单位为 MB  默认值为1
        }
      }
    }
  },
  watch: {
    dataInfo: {
      handler(val) {
        if (Object.prototype.toString.call(val) === '[object Object]' && Object.keys(val).length > 0) {
          const { tips, dataTips, data, status,resTitle, cancelLabel,confirmLabel,cancelEventName,confirmEventName, cancelType,confirmType, cancelAttr={},confirAttr={} } = val
          this.cancelConfig.label = cancelLabel
          this.cancelConfig.eventName = cancelEventName?cancelEventName:'default'
          this.confirmConfig.label = confirmLabel
          this.confirmConfig.eventName = confirmEventName?confirmEventName:'default'

          this.cancelConfig.type = cancelType?cancelType:''
          this.confirmConfig.type = confirmType?confirmType :''
          this.cancelConfig.attr = {...cancelAttr}
          this.confirmConfig.attr = {...confirAttr}
          this.status = status
          this.resTitle = resTitle
          // this.tips = tips
          // this.config.upLoadCardListConfig[0].tips = dataTips
          this.param.fileStatus = setNodeTypeList[data.setNodeType]
          this.param.id = data.taxId
          // console.log('dataInfo===>',data);
        }
      },
      deep: true,
      immediate: true
    },
  },
  methods: {
    btnEventClosed(){
      if( this.cancelConfig.eventName == 'default'){
        this.closeEvent('Refresh')
      } else {
        this.closeEvent(this.cancelConfig.eventName)
      }
    },
    btnEventNew() {
      if(this.confirmConfig.eventName == 'default'){
        this.param.files = []
        getDataForDB('税务办理上传首次税务办理登记,或实名认证截图', this.param).then(res => {
          // console.log('税务办理上传首次税务办理登记,或实名认证截图===>',res);
          if (res.code == 200) {
            this.$message.success('保存成功')
            this.closeEvent('Refresh')
          }
          if (res.code != 200) {
            this.$message.error(res.message)
          }
        })
      }else {
        this.closeEvent(this.confirmConfig.eventName)
      }
    },
    btnEvent() {
      const checkRes = this.$refs.iic.getDataCheckRes()
      console.log(checkRes);
      if (checkRes.indexOf(false) == -1) {
        const ll = this.$refs.iic.getData()
        const tempArr = []
        ll.forEach(element => {
          const { url, name } = element
          tempArr.push({ "fileName": name, "fileUrl": url })
        });
        this.param.files = tempArr
        getDataForDB('税务办理上传首次税务办理登记,或实名认证截图', this.param).then(res => {
          // console.log('税务办理上传首次税务办理登记,或实名认证截图===>',res);
          if (res.code == 200) {
            this.$message.success('保存成功')
            this.closeEvent('Refresh')
          }
          if (res.code != 200) {
            this.$message.error(res.message)
          }

        })
        // console.log('btnEvent', ll, this.param);
      }
    },
  }
}
</script>

<style lang="less">
.improve-information-con {
  .title {
    font-size: 18px;
    font-family: PingFangSC-Regular, PingFang SC;
    font-weight: 400;
    color: #333333;
    display: flex;

  }

  .body {
    width: 100%;
    height: 100%;
    overflow: auto;

    .btn-group {
      width: 100%;
      // height: 80px;
      padding: 5px 20px;
      display: flex;
      justify-content: center;
      align-items: center;
      .btn-item{
        flex: 1;
        display: flex;
        align-items: center;
        padding: 5px 10px;
      }
      .btn-item:nth-child(1){
        justify-content:flex-end;
      }
      .btn-item:nth-child(2){
        justify-content:flex-start;
      }
    }
  }
}
</style>
